# -*- coding: UTF-8 -*-

import Net
import time
import threading

def test(index):
    socket = Net.connect("127.0.0.1", 9999)
    print "连接服务器"

    req = "{'userName':'wq'}"
    Net.sendMessage(socket, 1, req)
    print '发送CS_LOGIN_REQUEST'

    id, msg = Net.receiveMessage(socket)
    print '登录回复信息:' + str(id) + ':' + msg

#######################创建角色#####################################
    req = "{'userName':'wq', 'nickName':'mark', 'sex':1}"
    Net.sendMessage(socket, 3, req)
    print '发送CS_LOGIN_CREATE_ROLE_REQUEST'
    id, msg = Net.receiveMessage(socket)
    print '创建角色登录回复信息:' + str(id) + ":" + msg

    id, msg = Net.receiveMessage(socket)
    print '创建角色后直接进入场景回复信息:' + str(id) + ":" + msg

#########################选择角色直接登录###################################################
    # req = "{'userName':'wq'}"
    # Net.sendMessage(socket, 5, req)
    # print '发送CS_LOGIN_SELECT_ROLE_ENTER_REQUEST'
    # id, msg = Net.receiveMessage(socket)
    # print '选择角色登录回复信息:' + str(id) + ":" + msg

    while True:
        pass

for i in xrange(1):
    t = threading.Thread(target=test, args=(i,))
    t.start()
    time.sleep(0.1)
